<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <title>用户-区域配置</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/dist/plugins/webuploader-0.1.5/webuploader.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
</head>
<body>

<section class="content text-center" id="app">
    <div class="box-body no-padding box-border" style="overflow: auto;background: #f7f8fa;">
        <ul class="ztree" id="ulRegion"></ul>
    </div>
    <input type="button" value="保存" id="btnSave" class="btn oaBtn btn-sm"
           style="margin-top:10px;">
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script type="text/javascript">
    var zTreeRight_setting = {
        view: {
            showIcon: function (treeId, treeNode) {
                return treeNode.type == "root" || treeNode.type == "rightFolder";
            }
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        check: {
            chkboxType: {"Y": "p", "N": "s"},
            enable: true
        }
    };
    var zTreeRegion_setting = {
        view: {
            showIcon: function (treeId, treeNode) {
                return treeNode.isParent;
            }
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        check: {
            chkboxType: {"Y": "ps", "N": "ps"},
            enable: true
        }
    };
    var zTreeRight = null;
    var zTreeRegion = null;
</script>
<script type="text/javascript">
    $(function () {
        $.wyui.postMethod(urlConfig.system.region.getTreeNodes, {userId: getCurrentUser().id}, function (nodes) {
            zTreeRegion = $.fn.zTree.init($("#ulRegion"), zTreeRegion_setting, nodes);
            $.wyui.postMethod(urlConfig.system.user2Region.getByUserId, {userId: $.wyui.page.urlParams.userId}, function (list) {
                for (var i = 0; i < list.length; i++) {
                    var node = zTreeRegion.getNodeByParam("id", list[i].regionId);
                    zTreeRegion.checkNode(node, true, false, false);
                    app.oldRegionIds.push(list[i].regionId);//获取旧区域ID
                }
            });
        });

        $("#btnSave").on("click", function () {
            var regionIds = new Array();
            var regionNodes = zTreeRegion.getCheckedNodes(true);
            console.log(regionNodes)

            for (var i = 0; i < regionNodes.length; i++) {
                if (regionNodes[i].type == "region") {
                    regionIds.push(regionNodes[i].id);
                }
            }
            $.wyui.postMethod(urlConfig.system.user2Region.config, {
                userId: $.wyui.page.urlParams.userId,
                regionIds: regionIds.join(","),
                updateUserId:getCurrentUser().id
            }, function (data) {
                var a = "'" + app.oldRegionIds.join("','") + "'," + "'" + regionIds.join("','") + "'";
                $.wyui.postMethod('/bonus/updateBonusMoney.json', {regionIds: a, type: 1}, function (data) {
                    //实时更新人员奖惩金额
                    console.log("成功")
                }, true);
                $.wyui.postMethod('/regionAchivementsService/initDataByUserId.json', {userId: $.wyui.page.urlParams.userId}, function (data) {
                    //给区域表插入目标
                }, true);
                $.wyui.postMethod('/regionAchivementsService/transferPosCountMoney.json', {userId: $.wyui.page.urlParams.userId}, function (data) {
                    //实时绩效奖惩金额
                }, true);
                var re ="'"+regionIds.join("','")+"'";
                    $.wyui.postMethod('/allCustomerReport/updateCustomerCreateByUserId.json', {
                        userId: $.wyui.page.urlParams.userId,
                        regionIds: re
                    }, function (data) {
                        //根据区域修改客户表中的客户创建者ID
                    }, true);
                alert("保存成功");
                var api = frameElement.api, W = api.opener;
                api.close();
            });
        });
    });

    var app = new Vue({
        el: '#app',
        data: {
            oldRegionIds: [],
            newRegionIds: []
        },
        methods: {},
        mounted: function () {
        }
    })


</script>

</body>
</html>
